#coding=utf-8

'''
1) 使用while和for…in两个循环分别输出四种九九乘法表效果（共计8个）。
'''


#用for循环左边打印九九乘法表
def use_for_left_one():
    for x in range(1, 10):
        for y in range(1, x+1):
            print("{}*{}={:<4}".format(x, y, x*y), end="")

        print("")
# use_for_left_one()

#用for循环左边打印九九乘法表
def use_for_left_two():
    for x in range(9, 0, -1):
        for y in range(1, x+1):
            print("{}*{}={:<4}".format(x, y, x * y), end="")

        print("")
# use_for_left_two()


#用for循环右边打印九九乘法表
def use_for_right_three():
    for x in range(1,10):
        for y in range(9, 0, -1):
            if x < y:
                print("{}{}{:<4}".format("  ", "  ", "  "), end="")

            else:
                print("{}*{}={:<4}".format(y, x, x * y), end="")
        print("")
# use_for_right_three()


#用for循环右边打印九九乘法表
def use_for_right_four():
    for x in range(9, 0, -1):
        for y in range(9,0,-1):
            if x < y:
                print("{}{}{:<4}".format("  ", "  ", "  "), end="")

            else:
                print("{}*{}={:<4}".format(y, x, x * y), end="")
        print("")
# use_for_right_four()


#用while循环左边打印九九乘法表
def use_while_left_one(num):
    x = 1
    y = 1
    while num > 0:
        while x >= y:
            print("{}*{}={:<4}".format(x, y, x * y), end="")
            y = y + 1
        print(" ")
        y = 1
        x = x + 1
        num = num -1
# use_while_left_one(9)

#用while循环左边打印九九乘法表
def use_while_left_two(num):
    x = 1
    y = num
    while num > 0:
        while x <= y:
            print("{}*{:}={:<5}".format(x, y, x * y), end="")
            x = x + 1
        print(" ")
        y = y - 1
        x = 1
        num = num - 1
# use_while_left_two(9)

#用while循环右边打印九九乘法表
def use_while_right_three():
    num = 9
    x = 9
    y = 1
    index = 1
    while num > 0:
        while index < 10:

            if num > index :
                print("{}{}{:<4}".format("  ", "  ", "  "), end="")
                x = x - 1
            else:
                print("{}*{}={:<4}".format(x, y, x * y), end="")
                x = x - 1
            index = index + 1
        x = 9
        y = y + 1
        print(" ")
        index =1
        num = num - 1

# use_while_right_three()

#用while循环右边打印九九乘法表
def use_while_right_four():
    num = 9
    x = 9
    y = 9
    index = 1
    while num > 0:
        while index < 10:

            if num >= x :
                print("{}*{}={:<4}".format(x, y, x * y), end="")
                x = x - 1
            else:
                print("{}{}{:<4}".format("  ", "  ", "  "), end="")

                x = x - 1
            index = index + 1
        x = 9
        y = y - 1
        print(" ")
        index =1
        num = num - 1

use_while_right_four()